package com.meida.student.app.scholartyrant.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.base.utils.FlymeUtils;
import com.meida.common.mybatis.interceptor.SaveInterceptor;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.query.CriteriaSave;
import com.meida.common.security.OpenHelper;
import com.meida.module.user.client.entity.AppEducational;
import com.meida.module.user.client.entity.AppWorkhistory;
import org.springframework.stereotype.Component;

@Component("AppWorkhistorySaveHandler")
public class AppWorkhistorySaveHandler implements SaveInterceptor<AppWorkhistory> {

    @Override
    public ResultBody validate(CriteriaSave cs, EntityMap params) {
        String positionName = params.get("positionName");
        if (FlymeUtils.isEmpty(positionName)) {
            return ResultBody.failed("请填写职位");
        }
        String companyAddress = params.get("companyAddress");
        if (FlymeUtils.isEmpty(companyAddress)) {
            return ResultBody.failed("请填写公司地址");
        }
        String workingDate = params.get("workingDate");
        if (FlymeUtils.isEmpty(workingDate)) {
            return ResultBody.failed("请选择工作时间");
        }
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaSave criteriaSave, EntityMap entityMap, AppWorkhistory appWorkhistory) {
        Long userId = OpenHelper.getUserId();
        appWorkhistory.setUserId(userId);
        appWorkhistory.setState(0);
    }


}
